#ifndef __PCA9685_H__
#define __PCA9685_H__

/* public interface */
/*
 * you have to succeed to pwm_sgrt_init(),
 * before you call the other interfaces.
 * And do the following steps:
 *  1. pwm_sgrt_init();
 *  2. pwm_sgrt_reset();
 *  3. pwm_sgrt_setfrq();
 * after that you can call set the PWM-out.
 *
 * @lednum must be less than 16 and greater than -1.
 * @onTime must be less than 4096 and greater than -1.
 * @offTime, the range of it is the same as @onTime.
 *
 * output-duty-factor: (offTime > onTime)
 *      ((offTime - onTime) / 4095)%
 *
 * About the details of output-duty-factor calculation,
 * you have to refer the pca9685-manual-7.3.3.
 *
 * pwm_sgrt_setfrq(), as the inaccuracy of the pca9685,
 * @out_freq will not be the actual output-freq.
 * So you have to adjust @out_freq with oscillograph,
 * the make sure the real-out-freq is correct.
 */

int pwm_sgrt_init(void);
int pwm_sgrt_exit(void);

unsigned char pwm_sgrt_reset(void);
unsigned char pwm_sgrt_setfrq(unsigned char out_freq);

unsigned char pwm_sgrt_setPWMout_on(unsigned char lednum,
        unsigned short onTime);
unsigned char pwm_sgrt_setPWMout_off(unsigned char lednum,
        unsigned short offTime);

unsigned char pwm_sgrt_setPWMout(unsigned char lednum,
        unsigned short onTime,
        unsigned short offTime) {
    pwm_sgrt_setPWMout_on(lednum, onTime);
    pwm_sgrt_setPWMout_off(lednum, offTime);
}
#endif
